package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/user/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/getEstimatedDeliveryTime")
    public Result getEstimatedDeliveryTime(Integer shopId,String customerAddress){
        String costTime= orderService.getEstimatedDeliveryTime(shopId,customerAddress);
        return Result.success(costTime);
    }

    /**
     * 用户提交订单
     * @param submitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result submit(@RequestBody OrdersSubmitDTO submitDTO){
        OrderSubmitVO submit = orderService.submit(submitDTO);
        return Result.success(submit);
    }

    @ApiOperation("用户催单")
    @GetMapping("/reminder/{orderId}")
    public Result reminder(@PathVariable Long orderId){
//        orderService.reminderOrder(orderId);
        return Result.success();
    }


    @GetMapping("/historyOrders")
    public Result<PageResult> pageQuery(OrdersPageQueryDTO dto){
        PageResult pageResult= orderService.pageQueryHistoryOrders(dto);
        return Result.success(pageResult);
    }

    @GetMapping("/queryOrdersCheckStatus")
    public Result<PageResult> pageQueryRefund(OrdersPageQueryDTO dto){
        PageResult pageResult= orderService.pageQueryRefundOrders(dto);
        return Result.success(pageResult);
    }

    @GetMapping("/orderDetail/{orderId}")
    public Result<OrderVO> selectOrderDetail(@PathVariable Long orderId){
        OrderVO orderVO = orderService.selectOrderDetail(orderId);
        return Result.success(orderVO);
    }

    @PostMapping("/cancel/{id}")
    public Result cancelOrder(@PathVariable Long id){
        orderService.cancelOrder(id);
        return Result.success();
    }

    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id){
        orderService.repetition(id);
        return Result.success();
    }

}

